package com.kim.whereeat.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by 伟阳 on 2015/10/24.
 */
public class SQLiteHelper extends SQLiteOpenHelper {

    private static final String name = "whereeat.db";
    private static final int version = 1;

    public SQLiteHelper(Context context) {
        super(context, name, null, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String storeinfoSql = "CREATE TABLE storeinfo (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "user_id INTEGER NOT NULL, " +
                "store_name VARCHAR (64) NOT NULL, " +
                "store_introduction VARCHAR (128) NOT NULL, " +
                "store_image VARCHAR (64) NOT NULL, " +
                "store_address VARCHAR (64) NOT NULL, " +
                "store_phone VARCHAR (64) NOT NULL, " +
                "store_business_hours_start VARCHAR (64) NOT NULL, " +
                "store_business_hours_end VARCHAR (64) NOT NULL); ";
        String storecommentSql = "CREATE TABLE storecomment (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "store_id INTEGER NOT NULL, " +
                "user_id INTEGER NOT NULL, " +
                "title VARCHAR (64) NOT NULL, " +
                "content VARCHAR (128) NOT NULL, " +
                "time VARCHAR (64) NOT NULL, " +
                "star DOUBLE NOT NULL); ";
        String foodinfoSql = "CREATE TABLE foodinfo (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "food_name VARCHAR (64) NOT NULL, " +
                "food_price DOUBLE NOT NULL, " +
                "food_image VARCHAR (64) NOT NULL, " +
                "food_introduction VARCHAR (128) NOT NULL, " +
                "store_id INTEGER NOT NULL); ";
        String userinfoSql = "CREATE TABLE userinfo (" +
                "id integer PRIMARY KEY AUTOINCREMENT, " +
                "username VARCHAR (64), " +
                "password VARCHAR (64)); ";
        String foodcommentSql = "CREATE TABLE foodcomment (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "food_id INTEGER NOT NULL, " +
                "user_id INTEGER NOT NULL, " +
                "title VARCHAR (64) NOT NULL, " +
                "content VARCHAR (128) NOT NULL, " +
                "time VARCHAR (64) NOT NULL, " +
                "star VARCHAR (64) NOT NULL);";
        db.execSQL(storeinfoSql);
        db.execSQL(storecommentSql);
        db.execSQL(foodinfoSql);
        db.execSQL(userinfoSql);
        db.execSQL(foodcommentSql);
        Log.d("SQLiteHelper", "------>>>>>create tables succeed!<<<<<------");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
